<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="../templates/popup.xhtml">
	<ui:define name="titre">#{lbl['menu.hub.arrival']}</ui:define>
	<ui:define name="popup_page">

		<!-- Fonction javascript pour la demande de rafraichissement du hub. -->
		<script language="javascript">
			function javascriptOnLoad(){
					self.opener.refreshHub();
				}
		</script>

		<!-- La liste des erreurs. -->
			<rich:messages />
		<h:form id="working_plan_form">
			<a4j:outputPanel id="working_plan_panel">
				<h:panelGroup>
					<h:outputText value="#{lbl['compo.working.plan.title']}" /> : 
			 		<h:outputText value="#{hubManaged.currentSillon.tcmsTrainId}" />
					<p />
				</h:panelGroup>
				<rich:extendedDataTable id="working_plan_table"
					style="width:1395px;height:580px;border:none;"
					rowClasses="rich_datagrid_even_line, rich_datagrid_odd_line"
					value="#{hubManaged.lstCompositions}" var="composition"
					iterationStatusVar="it">

					<f:facet name="noData">
						<h:outputText value="#{msg['msg.info.nodata']}" />
					</f:facet>

					<rich:column width="60px" style="text-align:center;">
						<f:facet name="header">
							<h:outputText value="#{lbl['compo.rail.arrival']}" />
						</f:facet>
						<h:outputText value="#{lbl['common.nc']}"
							rendered="#{hubManaged.currentSillon.railId == 0}" />
						<h:outputText value="#{hubManaged.currentSillon.railExtId}"
							rendered="#{hubManaged.currentSillon.railId ne 0}" />
					</rich:column>

					<rich:column width="55px" styleClass="rich_datagrid_pos_line"
						style="text-align:center;">
						<f:facet name="header">
							<h:outputText value="#{lbl['common.position']}" />
						</f:facet>

						<h:panelGrid id="nv_#{composition.id}" columnClasses="_center"
							width="60px" border="0" cellpadding="0" cellspacing="0"
							style="background-color:#{composition.wagon.hexColor};"
							styleClass="rich_datagrid_pos_line">
							<h:outputText value="#{composition.wagon.currentPos.posNum+1}" />
						</h:panelGrid>
					</rich:column>

					<rich:column width="90px" style="text-align:left;">
						<f:facet name="header">
							<h:outputText value="#{lbl['compo.destination.label']}" />
						</f:facet>
						<h:outputText value="#{composition.destinationLabel}" />
					</rich:column>

					<rich:column width="100px" style="text-align:center;">
						<f:facet name="header">
							<h:outputText value="#{lbl['common.wagon']}" />
						</f:facet>
						<h:outputText value="#{composition.wagon.extId}">
							<f:converter converterId="extIdWagonConverter" />
						</h:outputText>
					</rich:column>

					<!-- Test en temps réel pour le changement de voie. -->
					<rich:column width="110px" style="text-align:center;">
						<f:facet name="header">
							<h:outputText value="#{lbl['compo.rail']}" />
						</f:facet>
						<h:selectOneMenu id="railId"
							onchange="moveWagonForWorkingPlan(#{it.index},this.value);"
							value="#{composition.wagon.nextPos.posRailId}">
							<f:selectItems value="#{repositoryManaged.lstSortRails}" />
						</h:selectOneMenu>
					</rich:column>

					<rich:column width="600px" style="text-align:left;">
						<f:facet name="header">
							<h:outputText value="#{lbl['common.comment']}" />
						</f:facet>
						<rich:inplaceInput id="comment" value="#{composition.comment}"
							showControls="false" inputWidth="255" />
					</rich:column>

					<rich:column width="35px">
						<f:facet name="header">
							<h:outputText value="#{lbl['common.fault.indicator']}" />
						</f:facet>
						<h:graphicImage value="../../imgs/icons/ico_error_20x20.png"
							rendered="#{composition.wagon.errorIndicator}">
						</h:graphicImage>
						<h:graphicImage value="../../imgs/icons/ico_info_20x20.png"
							rendered="#{!composition.wagon.errorIndicator}" />
					</rich:column>

					<rich:column width="334px" style="text-align:left;">
						<f:facet name="header">
							<h:outputText value="#{lbl['common.message']}" />
						</f:facet>
						<h:outputText value="#{composition.wagon.errorMessage}" />
					</rich:column>
				</rich:extendedDataTable>

				<!-- Le panneau pour les boutons. -->
				<h:panelGrid columns="3" id="working_plan_command_panel"
					columnClasses="_left, _center, _right" style="width:100%">
					<a4j:commandButton value="#{lbl['common.button.cancel']}"
						action="#{hubManaged.refreshHub}">
						<a4j:param name="fromOutcome" value="arrival_success"
							assignTo="#{hubManaged.criterion.fromOutCome}" />
					</a4j:commandButton>

					<h:outputText value="#{lbl['common.alert.close']}"
						style="color:#FF0000;font-weight: bold;" />

					<a4j:commandButton value="#{lbl['common.button.validate']}"
						action="#{hubManaged.requestWorkingPlan}" />
				</h:panelGrid>
			</a4j:outputPanel>

			<!-- Méthode pour faire le déplacement d'un wagon. -->
			<a4j:jsFunction name="moveWagonForWorkingPlan"
				render="working_plan_panel" execute="@form"
				oncomplete="self.opener.refreshHub();"
				action="#{hubManaged.moveWagonForWorkingPlan}" immediate="true">
				<a4j:param name="idx" assignTo="#{hubManaged.criterion.idx}" />
				<a4j:param name="railId"
					assignTo="#{hubManaged.criterion.posRailId}" />
			</a4j:jsFunction>
		</h:form>
	</ui:define>
</ui:composition>
</html>